home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3.iso / chapte19 / devcaps.c < prev    next >
C/C++ Source or Header  |  1996-04-29  |  13KB  |  457 lines

  1.  
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include "DevCaps.h"
  5. #include <vfw.h>
  6.  
  7. #if defined (WIN32)
  8.     #define IS_WIN32 TRUE
  9. #else
  10.     #define IS_WIN32 FALSE
  11. #endif
  12.  
  13. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  14. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  15. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  16.  
  17. HINSTANCE hInst;   // current instance
  18.  
  19. LPCTSTR lpszAppName = "MyApp";
  20. LPCTSTR lpszTitle   = "My Application"; 
  21.  
  22.  
  23. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  24.  
  25.  
  26. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  27.                       LPTSTR lpCmdLine, int nCmdShow)
  28. {
  29.    MSG      msg;
  30.    HWND     hWnd; 
  31.    WNDCLASS wc;
  32.  
  33.    wc.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  34.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  35.    wc.cbClsExtra    = 0;                      
  36.    wc.cbWndExtra    = 0;                      
  37.    wc.hInstance     = hInstance;              
  38.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  39.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  40.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  41.    wc.lpszMenuName  = lpszAppName;              
  42.    wc.lpszClassName = lpszAppName;              
  43.  
  44.    if ( IS_WIN95 )
  45.    {
  46.       if ( !RegisterWin95( &wc ) )
  47.          return( FALSE );
  48.    }
  49.    else if ( !RegisterClass( &wc ) )
  50.       return( FALSE );
  51.  
  52.    hInst = hInstance; 
  53.  
  54.    hWnd = CreateWindow( lpszAppName, 
  55.                         lpszTitle,    
  56.                         WS_OVERLAPPEDWINDOW, 
  57.                         CW_USEDEFAULT, 0, 
  58.                         CW_USEDEFAULT, 0,  
  59.                         NULL,              
  60.                         NULL,              
  61.                         hInstance,         
  62.                         NULL               
  63.                       );
  64.  
  65.    if ( !hWnd ) 
  66.       return( FALSE );
  67.  
  68.    ShowWindow( hWnd, nCmdShow ); 
  69.    UpdateWindow( hWnd );         
  70.  
  71.    while( GetMessage( &msg, NULL, 0, 0) )   
  72.    {
  73.       TranslateMessage( &msg ); 
  74.       DispatchMessage( &msg );  
  75.    }
  76.  
  77.    return( msg.wParam ); 
  78. }
  79.  
  80.  
  81. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  82. {
  83.     WNDCLASSEX wcex;
  84.  
  85.    wcex.style         = lpwc->style;
  86.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  87.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  88.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  89.    wcex.hInstance     = lpwc->hInstance;
  90.    wcex.hIcon         = lpwc->hIcon;
  91.    wcex.hCursor       = lpwc->hCursor;
  92.    wcex.hbrBackground = lpwc->hbrBackground;
  93.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  94.    wcex.lpszClassName = lpwc->lpszClassName;
  95.  
  96.    // Added elements for Windows 95.
  97.    //...............................
  98.    wcex.cbSize = sizeof(WNDCLASSEX);
  99.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  100.                             IMAGE_ICON, 16, 16,
  101.                             LR_DEFAULTCOLOR );
  102.             
  103.    return RegisterClassEx( &wcex );
  104. }
  105.  
  106. #define MSG_LEN          1024
  107.  
  108. char       msg[MSG_LEN+1];
  109. int        nTabStop = 100;
  110. HWND       hListBox = NULL;
  111. HWND       hMCIWnd  = NULL;   // MCIWnd window handle
  112.  
  113. VOID GetMCIWndInfo();
  114.  
  115.  
  116. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  117. {
  118.    switch( uMsg )
  119.    {
  120.       case WM_CREATE :
  121.               // Create ListBox
  122.               //...............
  123.  
  124.               hListBox = CreateWindow( "LISTBOX", "",    
  125.                                        WS_CHILD | LBS_NOTIFY | 
  126.                                        WS_VSCROLL | WS_BORDER | 
  127.                                        WS_VISIBLE | LBS_NOINTEGRALHEIGHT |
  128.                                        LBS_USETABSTOPS, 
  129.                                        0, 0, 
  130.                                        0, 0,  
  131.                                        hWnd,              
  132.                                        (HMENU)101,              
  133.                                        hInst,         
  134.                                        NULL );
  135.               SendMessage(hListBox, LB_SETTABSTOPS, 1, (LPARAM)&nTabStop);
  136.               
  137.               // create MCIWnd window
  138.               //.....................
  139.  
  140.               hMCIWnd = MCIWndCreate(hWnd, hInst, 
  141.                                      WS_VISIBLE | WS_CHILD | 
  142.                                      WS_OVERLAPPEDWINDOW | WS_BORDER |
  143.                                      MCIWNDF_SHOWALL | MCIWNDF_NOTIFYMODE, 
  144.                                      NULL
  145.                                     );
  146.                           
  147.               if (!hMCIWnd)
  148.               {
  149.                   MessageBox(hWnd, "Error creating MCIWnd window...", 
  150.                              NULL, MB_OK);
  151.                   DestroyWindow( hWnd );
  152.               }
  153.               break;
  154.  
  155.       case WM_SIZE :
  156.               MoveWindow( hListBox, 0, 0, 
  157.                           LOWORD( lParam ), 
  158.                           HIWORD( lParam ), TRUE );
  159.               break;
  160.  
  161.       case WM_COMMAND :
  162.               switch( LOWORD( wParam ) )
  163.               {
  164.                  
  165.                  case IDM_AVIFILE :
  166.                         {
  167.                            MCIWndOpen(hMCIWnd, "sample.avi", NULL);
  168.                            GetMCIWndInfo();
  169.                            MCIWndClose(hMCIWnd);
  170.                         }
  171.                         break;
  172.                           
  173.                  case IDM_CDAUDIO :
  174.                         {
  175.                            MCIWndOpen(hMCIWnd, "cdaudio", NULL);
  176.                            GetMCIWndInfo();
  177.                            MCIWndClose(hMCIWnd);
  178.                         }
  179.                         break;
  180.  
  181.                  case IDM_MIDIAUDIO :
  182.                         {
  183.                            MCIWndOpen(hMCIWnd, "sample.mid", NULL);
  184.                            GetMCIWndInfo();
  185.                            MCIWndClose(hMCIWnd);
  186.                         }
  187.                         break;
  188.  
  189.                  case IDM_WAVEFORM :
  190.                         {
  191.                            MCIWndOpen(hMCIWnd, "sample.wav", NULL);
  192.                            GetMCIWndInfo();
  193.                            MCIWndClose(hMCIWnd);
  194.                         }
  195.                         break; 
  196.                  
  197.                  case IDM_ABOUT :
  198.                         DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  199.                         break;
  200.  
  201.                  case IDM_EXIT :
  202.                         DestroyWindow( hWnd );
  203.                         break;
  204.               }
  205.               break;
  206.  
  207.       case WM_DESTROY :
  208.               // destroy MCIWnd, if one exists
  209.               //..............................
  210.  
  211.               if (hMCIWnd)
  212.                   MCIWndDestroy(hMCIWnd);
  213.  
  214.               PostQuitMessage(0);
  215.               break;
  216.  
  217.       default :
  218.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  219.    }
  220.  
  221.    return( 0L );               
  222. }
  223.  
  224.  
  225. #define Display(s)   SendMessage(hListBox, LB_ADDSTRING, 0, (LPARAM)s)
  226.  
  227. VOID GetMCIWndInfo(HWND hWnd) 
  228. {
  229.    RECT rect;
  230.    char cTmp[MSG_LEN];
  231.    
  232.    SendMessage(hListBox, LB_RESETCONTENT, 0, 0);
  233.    
  234.    // MCIWndGetDevice
  235.  
  236.    MCIWndGetDevice(hMCIWnd, cTmp, MSG_LEN);
  237.    sprintf(msg, "MCIWndGetDevice:\t %s", cTmp);
  238.    Display(msg);
  239.    Display("");
  240.  
  241.    // MCIWndCanConfig
  242.  
  243.    sprintf(msg, "MCIWndCanConfig:\t %s", 
  244.            (MCIWndCanConfig(hMCIWnd) ? "Yes" : "No") );
  245.    Display(msg);
  246.  
  247.    // MCIWndCanEject
  248.  
  249.    sprintf(msg, "MCIWndCanEject:\t %s",
  250.            (MCIWndCanEject(hMCIWnd) ? "Yes" : "No") );
  251.    Display(msg);
  252.  
  253.    // MCIWndCanPlay
  254.  
  255.    sprintf(msg, "MCIWndCanPlay:\t %s", 
  256.            (MCIWndCanPlay(hMCIWnd) ? "Yes" : "No") );
  257.    Display(msg);
  258.  
  259.    // MCIWndCanRecord
  260.  
  261.    sprintf(msg, "MCIWndCanRecord:\t %s", 
  262.            (MCIWndCanRecord(hMCIWnd) ? "Yes" : "No") );
  263.    Display(msg);
  264.  
  265.    // MCIWndCanSave
  266.  
  267.    sprintf(msg, "MCIWndCanSave:\t %s", 
  268.            (MCIWndCanSave(hMCIWnd) ? "Yes" : "No") );
  269.    Display(msg);
  270.  
  271.    // MCIWndCanWindow
  272.  
  273.    sprintf(msg, "MCIWndCanWindow:\t %s", 
  274.            (MCIWndCanWindow(hMCIWnd) ? "Yes" : "No") );
  275.    Display(msg);
  276.  
  277.    // MCIWndGetActiveTimer
  278.    //
  279.    // NOTE: As of this writing, an error exists in the VFW.H 
  280.    //       file distributed with the WIN32SDK. The macro 
  281.    //       definition is incorrectly terminated by a semi-colon. 
  282.    //       The semi-colon must be removed if this macro is to be 
  283.    //       used in an expression, or the compiler will generate errors.
  284.  
  285.  
  286.    sprintf(msg, "MCIWndGetActiveTimer:\t %ld", 
  287.            MCIWndGetActiveTimer(hMCIWnd));
  288.    Display(msg);
  289.  
  290.    // MCIWndGetAlias
  291.  
  292.    sprintf(msg, "MCIWndGetAlias:\t %ld", 
  293.            MCIWndGetAlias(hMCIWnd));
  294.    Display(msg);
  295.    
  296.    // MCIWndGetDest
  297.  
  298.    MCIWndGetDest(hMCIWnd, &rect);
  299.    
  300.    sprintf(msg, "MCIWndGetDest:\t left:%d, top:%d, right:%d, bottom:%d", 
  301.            rect.left, rect.top, rect.right, rect.bottom);
  302.    Display(msg);
  303.  
  304.    // MCIWndGetDeviceID
  305.    
  306.    sprintf(msg, "MCIWndGetDeviceID:\t %ld", 
  307.            MCIWndGetDeviceID(hMCIWnd));
  308.    Display(msg);
  309.  
  310.    // MCIWndGetEnd
  311.    
  312.    sprintf(msg, "MCIWndGetEnd:\t %ld", 
  313.            MCIWndGetEnd(hMCIWnd));
  314.    Display(msg);
  315.  
  316.    // MCIWndGetError
  317.    
  318.    sprintf(msg, "MCIWndGetError:\t %ld", 
  319.            MCIWndGetError(hMCIWnd, cTmp, MSG_LEN), cTmp);
  320.    Display(msg);
  321.  
  322.    // MCIWndGetFileName
  323.    
  324.    MCIWndGetFileName(hMCIWnd, cTmp, MSG_LEN);
  325.  
  326.    sprintf(msg, "MCIWndGetFileName:\t %s", cTmp);
  327.    Display(msg);
  328.  
  329.    // MCIWndGetInactiveTimer
  330.    //
  331.    // NOTE: As of this writing, an error exists in the VFW.H 
  332.    //       file distributed with the WIN32SDK. The macro 
  333.    //       definition is incorrectly terminated by a semi-colon. 
  334.    //       The semi-colon must be removed if this macro is to be 
  335.    //       used in an expression, or the compiler will generate errors.
  336.  
  337.    sprintf(msg, "MCIWndGetInactiveTimer:\t %ld", 
  338.            MCIWndGetInactiveTimer(hMCIWnd));
  339.    Display(msg);
  340.  
  341.    // MCIWndGetLength
  342.    
  343.    sprintf(msg, "MCIWndGetLength:\t %ld", 
  344.            MCIWndGetLength(hMCIWnd));
  345.    Display(msg);
  346.  
  347.    // MCIWndGetMode
  348.    
  349.    sprintf(msg, "MCIWndGetMode:\t %ld - %s", 
  350.            MCIWndGetMode(hMCIWnd, cTmp, MSG_LEN), cTmp);
  351.    Display(msg);
  352.  
  353.    // MCIWndGetPalette
  354.    
  355.    sprintf(msg, "MCIWndGetPalette:\t %ld", 
  356.            MCIWndGetPalette(hMCIWnd));
  357.    Display(msg);
  358.  
  359.    // MCIWndGetPosition
  360.    
  361.    sprintf(msg, "MCIWndGetPosition:\t %ld", 
  362.            MCIWndGetPosition(hMCIWnd));
  363.    Display(msg);
  364.  
  365.    // MCIWndGetPositionString
  366.    
  367.    sprintf(msg, "MCIWndGetPositionString:\t %ld - %s", 
  368.            MCIWndGetPositionString(hMCIWnd, cTmp, MSG_LEN), cTmp);
  369.    Display(msg);
  370.  
  371.    // MCIWndGetRepeat
  372.    
  373.    sprintf(msg, "MCIWndGetRepeat:\t %s", 
  374.            (MCIWndGetRepeat(hMCIWnd) ? "Repeat mode ON" : 
  375.                                        "Repeat mode OFF") );
  376.    Display(msg);
  377.  
  378.    // MCIWndGetSource
  379.    
  380.    MCIWndGetSource(hMCIWnd, &rect);
  381.  
  382.    sprintf(msg, "MCIWndGetSource:\t left:%d, top:%d, right:%d, bottom:%d", 
  383.            rect.left, rect.top, rect.right, rect.bottom);
  384.    Display(msg);
  385.  
  386.    // MCIWndGetSpeed
  387.    
  388.    sprintf(msg, "MCIWndGetSpeed:\t %ld", 
  389.            MCIWndGetSpeed(hMCIWnd));
  390.    Display(msg);
  391.  
  392.    // MCIWndGetStart
  393.    
  394.    sprintf(msg, "MCIWndGetStart:\t %ld", 
  395.            MCIWndGetStart(hMCIWnd));
  396.    Display(msg);
  397.  
  398.    // MCIWndGetStyles
  399.    
  400.    sprintf(msg, "MCIWndGetStyles:\t %ld", 
  401.            MCIWndGetStyles(hMCIWnd));
  402.    Display(msg);
  403.  
  404.    // MCIWndGetTimeFormat
  405.    
  406.    sprintf(msg, "MCIWndGetTimeFormat:\t %ld", 
  407.            MCIWndGetTimeFormat(hMCIWnd, cTmp, MSG_LEN), cTmp);
  408.    Display(msg);
  409.  
  410.    // MCIWndGetVolume
  411.    
  412.    sprintf(msg, "MCIWndGetVolume:\t %ld", 
  413.            MCIWndGetVolume(hMCIWnd));
  414.    Display(msg);
  415.  
  416.    // MCIWndGetZoom
  417.    
  418.    sprintf(msg, "MCIWndGetZoom:\t %ld%c",
  419.            MCIWndGetZoom(hMCIWnd), '%');
  420.    Display(msg);
  421. }
  422.  
  423.  
  424. LRESULT CALLBACK About( HWND hDlg,           
  425.                         UINT message,        
  426.                         WPARAM wParam,       
  427.                         LPARAM lParam)
  428. {
  429.    switch (message) 
  430.    {
  431.        case WM_INITDIALOG: 
  432.                return (TRUE);
  433.  
  434.        case WM_COMMAND:                              
  435.                if (   LOWORD(wParam) == IDOK         
  436.                    || LOWORD(wParam) == IDCANCEL)    
  437.                {
  438.                        EndDialog(hDlg, TRUE);        
  439.                        return (TRUE);
  440.                }
  441.                break;
  442.    }
  443.  
  444.    return (FALSE); 
  445. }
  446.  
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453.  
  454.  
  455.  
  456.  
  457.